package com.zixuan.gulicollege.video.controller;

import com.zixuan.gulicollege.common_utils.R;
import com.zixuan.gulicollege.video.service.VideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @ClassName: VideoController
 * @Author: zixuan
 * @Date: 2021/5/12 20:30
 * @Description:
 */
@RestController
@RequestMapping("/edu_vod/video")
public class VideoController {

    @Autowired
    private VideoService videoService;

    /**
     * 上传视频接口
     * @param file
     * @return
     */
    @PostMapping("/uploadAliyunVideo")
    public R uploadAliyunVideo(MultipartFile file){
        String videoId = videoService.uploadVideo(file);
        return R.ok().data("videoId", videoId);
    }

    /**
     * 删除视频接口
     */
    @DeleteMapping("/removeAliyunVideo/{id}")
    public R deleteAliyunVideo(@PathVariable String id) {
        videoService.deleteAliyunVideo(id);
        return R.ok();
    }

    /**
     * 删除多个视频
     * @param videoListId
     * @return
     */
    @DeleteMapping("/deleteBatch")
    public R deleteBatch(@RequestParam("videoListId") List<String> videoListId) {
        videoService.deleteBatch(videoListId);
        return R.ok();
    }

    /**
     * 获取视频播放凭证
     * @return
     */
    @GetMapping("/getPlayAuth/{id}")
    public R getPlayAuth(@PathVariable String id) {
        String playAuth = videoService.getPlayAuth(id);
        return R.ok().data("playAuth", playAuth);
    }

}
